package ${package.Svc};

import org.springframework.stereotype.Service;
import ${package.Iservice}.I${entity}Service;
import com.github.pagehelper.PageInfo;
import ${package.Das}.${entity}Das;
import com.dtyunxi.cube.commons.dto.DtoHelper;
import javax.annotation.Resource;
import ${package.Requestdto}.${entity}ReqDto;
import ${package.Responsedto}.${entity}RespDto;
import ${package.Eo}.${entity}Eo;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.dtyunxi.cube.utils.bean.CubeBeanUtils;
import java.util.ArrayList;
import java.util.List;

/**
* ${table.comment}服务实现类
*
* @author ${author}
* @since ${date}
*/
@Service
public class ${entity}ServiceImpl implements I${entity}Service {

    @Resource
    private ${entity}Das ${entity?uncap_first}Das;

    @Override
    public Long add${entity}(${entity}ReqDto addReqDto) {
        ${entity}Eo ${entity?uncap_first}Eo = new ${entity}Eo();
        DtoHelper.dto2Eo(addReqDto, ${entity?uncap_first}Eo);
        ${entity?uncap_first}Das.insert(${entity?uncap_first}Eo);
        return ${entity?uncap_first}Eo.getId();
    }

    @Override
    public void modify${entity}(${entity}ReqDto modifyReqDto) {
        ${entity}Eo ${entity?uncap_first}Eo = new ${entity}Eo();
        DtoHelper.dto2Eo(modifyReqDto, ${entity?uncap_first}Eo);
        ${entity?uncap_first}Das.updateSelective(${entity?uncap_first}Eo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void remove${entity}(String ids,
                                   Long instanceId) {
        String[] removeIds = ids.split(",");
        for (String id : removeIds) {
            ${entity?uncap_first}Das.logicDeleteById(Long.valueOf(id));
        }
    }

    @Override
    public ${entity}RespDto queryById(Long id) {
        ${entity}Eo ${entity?uncap_first}Eo = ${entity?uncap_first}Das.selectByPrimaryKey(id);
        ${entity}RespDto ${entity?uncap_first}RespDto = new ${entity}RespDto();
        DtoHelper.eo2Dto(${entity?uncap_first}Eo, ${entity?uncap_first}RespDto);
        return ${entity?uncap_first}RespDto;
    }

    @Override
    public PageInfo<${entity}RespDto> queryByPage(String filter,
                                                    Integer pageNum,
                                                    Integer pageSize) {
        ${entity}ReqDto ${entity?uncap_first}ReqDto = JSON.parseObject(filter, ${entity}ReqDto.class);
        ${entity}Eo ${entity?uncap_first}Eo = new ${entity}Eo();
        DtoHelper.dto2Eo(${entity?uncap_first}ReqDto, ${entity?uncap_first}Eo);
        PageInfo<${entity}Eo> eoPageInfo = ${entity?uncap_first}Das.selectPage(${entity?uncap_first}Eo, pageNum, pageSize);

        PageInfo<${entity}RespDto> dtoPageInfo = new PageInfo();
        CubeBeanUtils.copyProperties(dtoPageInfo, eoPageInfo, "list", "navigatepageNums");
        List<${entity}RespDto> dtoList = new ArrayList<>();
        DtoHelper.eoList2DtoList(eoPageInfo.getList(), dtoList, ${entity}RespDto.class);
        dtoPageInfo.setList(dtoList);
        return dtoPageInfo;
    }

}
